#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <vector>
#include <set>
#include <queue>

using namespace std;
using LL = long long;
using PII = pair<int, int>;

const int N = 110;

int n;
bool row[N], col[N], rslash[N], nslash[N];
int cnt, t = 1;
int ans[N];

void dfs(int row){

    if(row == n + 1 ){

        if(t <= 3){
            t ++;
            for(int i = 1; i <= n; i ++){
                cout << ans[i] << " ";
            }
            cout << '\n';    
        }

        cnt ++;
        return;
    }

    for(int i = 1; i <= n; i ++){
        if(!col[i] && !rslash[row - i + 40] && !nslash[row + i]){
            col[i] = true;
            rslash[row - i + 40] = true;
            nslash[row + i] = true;
            ans[row] = i;
            dfs(row + 1);
            col[i] = false;
            rslash[row - i + 40] = false;
            nslash[row + i] = false;
        }
    }

}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n;
    dfs(1);
    cout << cnt << '\n';


    return 0;
}